/**
 * 定义事件库管理模块
 */
(function(window, angular, undefined) {
	var Module = angular.module(
			'water.apps.sw.systemConfig.operationJob.operationJobManager',
			[ 'water.entity.commonEntity' ]);

	Module.controller('operationJobManagerController', function($rootScope,
			$scope, $commonEntityService) {

		/**
		 * 新建model
		 */
		$scope.createModel={};
		/**
		 * 编辑model
		 */
		$scope.editModel={};
		/**
		 * 事件库数据
		 */
		$scope.dataList=[];
		/**
		 * 编辑对话框对象
		 */
		$scope.editDialog;
		/**
		 * 详情对话框对象
		 */
		$scope.detailDialog;
		/**
		 * 新增对话框
		 */
		$scope.createDialog;

		/**
		 * 新增按钮点击事件
		 */
		$scope.onCreateClick = function() {
			$scope.createModel = {};
			$scope.createDialog.open();
		}
		/**
		 * 提交事件
		 */
		$scope.onSubmitCreateClick = function(model) {
			$commonEntityService.createModel("OPERATION_JOB", model).then(
					function() {
						$scope.createDialog.close();
						_getList();
						$.messager.alert("保存成功", "保存成功", 'info');
					});
		}
		/**
		 * 编辑按钮点击事件
		 */
		$scope.onEditClick = function(key) {
			$commonEntityService.getModel("OPERATION_JOB", key).then(
					function(data) {
						$scope.editModel = data;
						$scope.editDialog.open();
					});
		}
		/**
		 * 编辑确认按钮点击事件
		 */
		$scope.onSubmitEditClick = function(model) {
			$commonEntityService.updateModel("OPERATION_JOB",model).then(function() {
				$.messager.alert("保存成功", "保存成功", 'info');
				_getList();
				$scope.editDialog.close();
			});

		}
		/**
		 * 详情按钮点击事件
		 */
		$scope.onDetailClick = function(key) {
			$commonEntityService.getModel("OPERATION_JOB", key).then(
					function(data) {
						$scope.detailModel = data;
						$scope.detailDialog.open();
					});
		}
		/**
		 * 删除按钮点击事件
		 */
		$scope.onDeleteClick = function(key) {
			$.messager.confirm("确认", "确定要删除这条记录吗？", function(r) {
				if (r) {
					$commonEntityService.deleteModel("OPERATION_JOB", key)
							.then(function() {
								$.messager.alert("删除成功", "删除成功", 'info');
								_getList();
							});
				}
			});
		}
		/**
		 * 刷新列表
		 */
		$scope.onRefreshClick = function() {
			_getList();
		}

		/**
		 * 获取列表
		 */
		function _getList() {
			$commonEntityService.getList("OPERATION_JOB", {}).then(
					function(data) {
						$scope.dataList = data.data;
					});
		}
		;

		_getList();
	});
}(window, angular));